import oracledb from 'oracledb'
import dbconfig from '../config/dbconfig.js'
function doRelease (connection) {
  connection.close(
    function (err) {
      if (err) { console.error('conn close err:' + err.message) }
    })
}
var getdbdata = function () {
  var p = new Promise((resolve, reject) => {
    console.log(1)
    oracledb.getConnection({
      user: dbconfig.user,
      password: dbconfig.password,
      connectString: dbconfig.connectString
    },
    function (err, connection) {
      if (err) {
        console.error('conn open err:' + err.message)
        return
      }
      connection.execute(
        'SELECT * from yhb', [], // bind value for :id
        function (err, result) {
          if (err) {
            console.error(err.message)
            doRelease(connection)

            reject(result)
          }

          resolve(result)

          // console.log(result.rows)
          doRelease(connection)
        })
    })
  })
  return p
}
export default getdbdata
